/*
Kiwi Editor is a framework for building WYSIWYG web editors.
Copyright (C) 2011  Roosevelt de Lima Sardinha

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

Contact the author at roosevelt1@gmail.com (Roosevelt) 
*/

function cursor(containerId)
{	
	thisObject = this;
	var container = document.getElementById(containerId);
	this.lastMouseUpLeft = 0;
	this.lastMouseUpTop = 0;
	this.lastMouseMoveLeft = 0;
	this.lastMouseMoveTop = 0;
	this.lastClickLeft = 0;
	this.lastClickTop = 0;
	this.lastMouseDownTop = 0;
	this.lastMouseDownTop = 0;

	this.getLeft = function(e)
	{
		var posx = 0;
		if (!e) var e = window.event;
		if (e.pageX) 	{
			posx = e.pageX;
		}
		else if (e.clientX) 	{
			posx = e.clientX + document.body.scrollLeft
				+ document.documentElement.scrollLeft;
		}
		return posx;
	}

	this.getTop =  function(e)
	{
		var posy = 0;
		if (!e) var e = window.event;
		if (e.pageY) 	{
			posy = e.pageY;
		}
		else if (e.clientY) 	{
			posy = e.clientY + document.body.scrollTop
				+ document.documentElement.scrollTop;
		}
		return posy;
	}

	this.getContainerLeft = function(){
		var obj = container;
		var curleft = 0;
		if (obj.offsetParent) {
			do {
				curleft += obj.offsetLeft;
			} while (obj = obj.offsetParent);
			return curleft;
		}
	}	

	this.getContainerTop = function(){
		var obj = container;
		var curtop = 0;
		if (obj.offsetParent) {
			do {
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
			return curtop;
		}
	}
	
//	container.onmouseup = function (e) {
//		thisObject.lastMouseUpLeft = thisObject.getLeft(e);
//		thisObject.lastMouseUpTop = thisObject.getTop(e);
//	}	
	
//	container.onmousemove = function (e) {
//		thisObject.lastMouseMoveLeft = thisObject.getLeft(e);
//		thisObject.lastMouseMoveTop = thisObject.getTop(e);
//	}	

//	container.onclick = function (e) {
//		thisObject.lastClickLeft = thisObject.getLeft(e);
//		thisObject.lastClickTop = thisObject.getTop(e);
//	}
	
//	container.onmousedown = function (e) {
//		thisObject.lastMouseDownLeft = thisObject.getLeft(e);
//		thisObject.lastMouseDownTop = thisObject.getTop(e);
//	}

}
